<template>
  <div class="pieEchart">
    <base-echart :options="pieOptions"></base-echart>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, computed } from 'vue';
import baseEchart from '@/base-ui/base-echart';
import { IChartDataType } from '../types/index';

// 传进来我在把他放在pieOptions里面, 再把pieOptions传给base-echart
const props = defineProps<{
  pieData: IChartDataType[];
}>();

// 为了使props传进来的数据都会得到实时的更新,我们使用computed.
// base-echart里面也要重新挂载options
const pieOptions = computed(() => ({
  /* title: {
    text: 'Referer of a Website',
    subtext: 'Fake Data',
    left: 'center'
  }, */
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'horizontal',
    left: 'left'
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: '50%',
      top: '20%',
      data: props.pieData,
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ]
}));
</script>

<style scoped lang="less"></style>
